package net.onceface.application.assembler;

import java.util.Set;

import net.onceface.application.dto.DisCountDTO;
import net.onceface.core.domain.DisCount;
import net.onceface.core.domain.Product;

public class DisCountAssembler {

	public static DisCountDTO toDTO(DisCount disCount){
		if(disCount == null){
			return null;
		}
		DisCountDTO result = new DisCountDTO();
		result.setId(disCount.getId());
		result.setVersion(disCount.getVersion());
		result.setThreshold(disCount.getThreshold());
		result.setTitle(disCount.getTitle());
		result.setType(disCount.getType());
		if(disCount.getCouponId() != null){
			result.setCouponId(disCount.getCouponId());
		}
		if(disCount.getDisCount() > 0){
			result.setDisCount(disCount.getDisCount());
		}
		if(disCount.getProducts() != null){
			result.setProducts(ProductAssembler.toDTOs(disCount.getProducts()));
		}
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public static DisCount toEntity(DisCountDTO disCount){
		if(disCount == null){
			return null;
		}
		DisCount result = new DisCount();
		result.setId(disCount.getId());
		result.setVersion(disCount.getVersion());
		result.setThreshold(disCount.getThreshold());
		result.setTitle(disCount.getTitle());
		result.setType(disCount.getType());
		if(disCount.getCouponId() != null){
			result.setCouponId(disCount.getCouponId());
		}
		if(disCount.getDisCount() > 0){
			result.setDisCount(disCount.getDisCount());
		}
		if(disCount.getProducts() != null){
			result.setProducts((Set<Product>) ProductAssembler.toEntities(disCount.getProducts()));
		}
		return result;
	}
	
}
